package com.qianf.qfoffice.service.impl;

import com.qianf.qfoffice.dao.ShowExerciseDao;
import com.qianf.qfoffice.entity.ShowExercise;
import com.qianf.qfoffice.service.ShowExerciseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ShowExerciseServiceImpl implements ShowExerciseService {
    
    @Autowired
    private ShowExerciseDao showExerciseDao;
    
    @Override
    public ShowExercise selectExerciseList() {

        List<String> showExerciseList = new ArrayList<>();
        List<Map> showExerciseNumList = new ArrayList<>();

        List<Map> maps = showExerciseDao.selectExerciseList();
        for (Map map : maps) {
            String category = (String) map.get("category");
            long num = (long) map.get("num");

            HashMap<String, Object> stringObjectHashMap = new HashMap<>();
            stringObjectHashMap.put("value",num);
            stringObjectHashMap.put("name",category);
            showExerciseList.add(category);
            showExerciseNumList.add(stringObjectHashMap);
        }
        ShowExercise showExercise = new ShowExercise(showExerciseList,showExerciseNumList);
        return showExercise;
    }
}
